{extend name="layouts:layout"/}
{block name="css_common"}
{asset:css name="jquery-layout,ztree,select2,export" /}
{/block}
{block name="js_common"}
{asset:js name="jquery-layout,ztree,select2,export" /}
{/block}
{block name="content"}

<div class="col-sm-12 search-collapse">
    <form id="role-form">
        <div class="select-list">
            <ul>
                <li>序号：<input type="text" name="where[id]" value=""></li>
                <li class="select-time">
                    <label>创建时间： </label>
                    <input type="text" name="between[create_time][start]" id="startTime" placeholder="开始时间"
                           readonly>
                    <span>-</span>
                    <input type="text" name="between[create_time][end]" id="endTime" placeholder="结束时间" readonly>
                </li>
                <li>状态：
                    <select name="eq[type]">
                        <option value="">全部</option>
                        <option value="1">回收中</option>
                        <option value="2">已回收</option>
                        <option value="3">已失效</option>
                    </select>
                <li>
                <li>
                    <a class="btn btn-primary btn-rounded btn-sm" onclick="$.table.search()"><i
                            class="fa fa-search"></i> 搜索</a>
                    <a class="btn btn-warning btn-rounded btn-sm" onclick="$.form.reset()"><i class="fa fa-refresh"></i>
                        重置</a>

                </li>
            </ul>
        </div>
    </form>
</div>

<div class="col-sm-12 search-collapse" style="display: flex;align-items: center;justify-content: space-between;">
    <ul class="nav nav-pills col-sm-6 " role="tablist">
        <li role="presentation"><a href="#">已发出 <span class="badge">{$total.sending_total}</span></a></li>
        <li role="presentation"><a href="#">回收中 <span class="badge">{$total.recycling_total}</span></a></li>
        <li role="presentation"><a href="#">已回收<span class="badge">{$total.achieve_total}</span></a></li>
        <li role="presentation"><a href="#">已失效 <span class="badge">{$total.expire_total}</span></a></li>
    </ul>
    <a class="btn btn-link" data-width="900" onclick="$.operate.add(this)"
       style="display: inline-block;background-color: #0171CF;color: white"><i class="fa fa-plus"></i> 新建合同</a>
</div>
<div class="col-sm-12" id="toolbar">
    <ul class="nav nav-tabs">
<!--        <li role="presentation" {if $type == ''}class="active"{/if}><a href="{:url('contract.contract/index')}">全部</a></li>-->
        <li role="presentation"{if $type == 1}class="active"{/if}><a href="{:url('contract.contract/index')}?type=1">学员合同</a></li>
        <li role="presentation"{if $type == 2}class="active"{/if}><a href="{:url('contract.contract/index')}?type=2">合伙人合同</a></li>
    </ul>
</div>
<div class="col-sm-12 select-table table-striped">
    <table id="bootstrap-table"></table>
</div>
{/block}

{block name="script"}
<script>
    var type = "{$type}";
    $(function () {
        var options = {
            modalName: "合同",
            sortName: 'id',
            showExport: true,
            exportOptions:{
                ignoreColumn:[0]
            },
            sortOrder: "desc",
            queryParams: function(params) {
                var curParams = {
                    // 传递参数查询参数
                    pageSize:       params.limit,
                    pageNum:        params.offset / params.limit + 1,
                    searchValue:    params.search,
                    orderByColumn:  params.sort,
                    isAsc:          params.order,
                    where:{type: type}
                };
                var currentId = $.common.isEmpty(table.options.formId) ? $('form').attr('id') : table.options.formId;
                return $.extend(curParams, $.common.formToJSON(currentId));
            },
            columns: [
                {checkbox: true},
                {field: 'id', title: '序号', align: 'center', sortable: true},
                {field: 'title', title: '合同名称', align: 'center'},
                {
                    field: 'type',
                    title: '类型',
                    align: 'center',
                    formatter: function (value, row, index) {
                        return $.myTool.statusShow(row, false, ['', '学员合同', '合伙人合同'], 'type', [], ['', '', 'primary']);
                    }
                },
                {
                    field: 'status',
                    title: '状态',
                    align: 'center',
                    formatter: function (value, row, index) {
                        return $.myTool.statusShow(row, false, ['', '回收中', '已回收', '已失效'], 'status', [], ['', '', 'info', 'danger']);
                    }
                },
                {field: 'initiator_cn', title: '发起人', align: 'center'},
                {field: 'recycling_num', title: '回收数量', sortable: true, align: 'center'},
                {field: 'sending_num', title: '发出数量', align: 'center'},
                {field: 'created_at', title: '发起时间', sortable: true, align: 'center'},
                {
                    title: '操作',
                    align: 'center',
                    formatter: function (value, row, index) {
                        var actions = [];
                        actions.push(`<a class="success" style="color: #1a7bb9" href="javascript:;" onclick="detail(${row.id},'${row.title}',${row.type})">详情</a> `);
                        if (row.type == 2) {
                            actions.push(`<a class="success" style="color: #00a65a" href="javascript:;" onclick="window.download(${row.id},'${row.title}')">下载合同</a>`);
                        } else {
                            actions.push(`<span class="success" style="color: #00a65a" href="javascript:;" onclick="addUser(${row.id},'${row.title}')">增加名单</span>`);
                        }
                        return actions.join('');
                    }
                }
            ]
        };
        $.table.init(options);
    });
    function addUser(id,title){
        table.set();
        $.modal.open(`增加【${title}】学员名单`,"{:url('admin/contract.contract/adduser')}?id="+id);
    }
    function detail(id,title,type){
        table.set();
        $.modal.open(`【${title}】详情`, $.operate.editUrl(id),type == 1 ? 1200:800);
    }

    function download(id,title){
        table.set();
        $.modal.open(`下载【${title}】`, "{:url('admin/contract.contract/download')}?id="+id,1200);
    }
</script>
{/block}

